package com.zyw.common.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class JsonUtil {

    private static final Logger logger = LoggerFactory.getLogger(JsonUtil.class);

    /**
     * 将对象转化为Json字符串
     *
     * @param bean
     * @return
     */
    public static String objectToJson(Object bean) {
        ObjectMapper objectMapper = new ObjectMapper();
        String jsonStr = null;
        try {
            jsonStr = objectMapper.writeValueAsString(bean);
        } catch (JsonProcessingException e) {
            logger.info("JsonUtil.objectToJson 调用异常，返回null：" + e.getMessage());
        }
        return jsonStr;
    }

}
